package com.dream.wukong.common.core.jdbc.generator;


import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.util.Assert;

/**
 * @Author: wuyichao
 * @Description:
 * @Date: Created in 10:14 2018/9/18.
 * @Modified:
 */
public class IdUtil {
    private NamedParameterJdbcOperations jdbc ;

    public  Object generateValue(  String idGeneratorType , String sequence){
        IdGenerator idGenerator  ;
        if(idGeneratorType.equals(SequenceGenerator.SEQUENCE)){
            Assert.notNull(jdbc, "JDBC is empty");
            SequenceGenerator seq = new SequenceGenerator();
            seq.setJdbc(jdbc);
            seq.setSequence(sequence);
            idGenerator = seq ;
        }else if (idGeneratorType.equals(IdentityGenerator.IDENTITY)){
            idGenerator = new IdentityGenerator();
        }else{
            idGenerator = new UuidGenerator();
        }
        return idGenerator.generateValue();
    }

    public void setJdbc(NamedParameterJdbcOperations jdbc) {
        this.jdbc = jdbc;
    }
}
